package com.xudm.cdg.service;

import cn.hutool.core.util.DesensitizedUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestAlgorithm;
import cn.hutool.crypto.digest.Digester;
import com.xudm.cdg.api.WxYiYanApi;
import com.xudm.cdg.entity.WxYiYanResult;
import com.xudm.cdg.utils.HttpClientUtil;
import org.springframework.stereotype.Component;

/**
 * 功能描述
 *
 * @author xudm
 */
@Component
public class FeatureDescriptionService {
    private final WxYiYanApi wxYiYanApi;
    private final RedisService redisService;

    public FeatureDescriptionService(WxYiYanApi wxYiYanApi, RedisService redisService) {
        this.wxYiYanApi = wxYiYanApi;
        this.redisService = redisService;
    }

    public String getFeatureDescription(String question) {
        Digester md5 = new Digester(DigestAlgorithm.MD5);
        String questionHex = md5.digestHex(question);
        String aswer = redisService.get(questionHex, String.class);
        if (StrUtil.isBlank(aswer)) {
            WxYiYanResult wxYiYanResult = wxYiYanApi.chatByErnie_lite_8k(question);
            aswer = wxYiYanResult.getResult();
            redisService.set(questionHex, aswer);
        }
        return aswer;
    }
}
